"""
系统管理模型
"""
from sqlalchemy import Column, String, Integer, Text, ForeignKey, DateTime, func
from sqlalchemy.orm import relationship
from .base import Base


class SystemConfig(Base):
    """系统配置表"""
    __tablename__ = "system_configs"
    
    config_key = Column(String(100), unique=True, nullable=False, comment="配置键")
    config_value = Column(Text, comment="配置值")
    description = Column(Text, comment="配置描述")
    
    def __repr__(self):
        return f"<SystemConfig(id={self.id}, config_key='{self.config_key}')>"


class SystemLog(Base):
    """系统日志表"""
    __tablename__ = "system_logs"
    
    user_id = Column(Integer, ForeignKey("employees.id"), comment="操作用户ID")
    action = Column(String(100), nullable=False, comment="操作动作")
    table_name = Column(String(50), comment="操作表名")
    record_id = Column(Integer, comment="记录ID")
    old_values = Column(Text, comment="旧值")
    new_values = Column(Text, comment="新值")
    ip_address = Column(String(45), comment="IP地址")
    user_agent = Column(Text, comment="用户代理")
    
    # 关系
    user = relationship("Employee", back_populates="system_logs")
    
    def __repr__(self):
        return f"<SystemLog(id={self.id}, user_id={self.user_id}, action='{self.action}')>"
